<?php
include "antet.php";
include "func.php";

if (isset ( $_SESSION ["user"] [0], $_GET ["town"] )) {
	$_GET ["town"] = clean ( $_GET ["town"] );
	$_SESSION ["user"] = user ( $_SESSION ["user"] [0] );
	$town = town ( $_GET ["town"] );
	if ($town [1] != $_SESSION ["user"] [0]) {
		header ( 'Location: login.php' );
		die ();
	}
	$buildings = buildings ( $_SESSION ["user"] [10] );
	if ($_SESSION ["user"] [11])
		$alliance = alliance_all ( $_SESSION ["user"] [11] );
	if ((isset ( $alliance )) && (! $alliance [0] [0])) {
		a_quit ( $_SESSION ["user"] [0] );
		$_SESSION ["user"] [11] = 0;
	}
	$c_status=get_con($_GET["town"]);
	$data = explode ( "-", $town [8] );
	$res = explode ( "-", $town [10] );
	$prod = explode ( "-", $town [9] );
	$lim = explode ( "-", $town [11] );
	

} else {
	header ( 'Location: login.php' );
	die ();
}
kepala($title." - ".$buildings[9][2]);
?>
<script type="text/javascript">
var prev="";
var tabLinks = new Array();
var contentDivs = new Array();
</script>
<script type="text/javascript">
var res_start0=<?php echo floor ( $res [0] );?>; 
var res_start1=<?php echo floor ( $res [1] );?>; 
var res_start2=<?php echo floor ( $res [2] );?>; 
var res_start3=<?php echo floor ( $res [3] );?>; 
var res_start4=<?php echo floor ( $res [4] );?>;
var res_limit0=<?php echo $lim [0];?>; 
var res_limit1=<?php echo $lim [1];?>; 
var res_limit2=<?php echo $lim [1];?>; 
var res_limit3=<?php echo $lim [1];?>; 
var res_limit4=<?php echo $lim [2];?>;
var res_ph0=<?php echo ($prod [0] - $town [3] - $town [12]);?>; 
var res_ph1=<?php echo ($prod [1]);?>; 
var res_ph2=<?php echo ($prod [2]);?>; 
var res_ph3=<?php echo ($prod [3]);?>; 
var res_ph4=<?php echo ($prod [4]);?>;
var res_sec0=0; var res_sec1=0; var res_sec2=0; var res_sec3=0; var res_sec4=0;
</script>
<script type="text/javascript">inittabs();</script>
<?php
		$to = 9;
		$output = "";
		$output .= buildingheader($to,$buildings,$data,$lim,$town);
		$output .= ads(0,"top");
		$output .= buildingstandard ( $town, $to, $lim, $buildings, $faction, $c_status, "good.png", $lang ['expSpeed'] );
		//$output .= buildingsub($town,$buildings,$to,0,$lim,$c_status);
		if ($data [9]) {
		$output .= $buildings [9] [8] . "</br></br></br>";
			if (! $_SESSION ["user"] [11])
		$output .= "<form name='form1' method='post' action='a_create.php?town=" . $_GET ["town"] . "'>
       " . $lang ['allyName'] . ": 
        <input class='textbox' type='text' name='name'>
        <input class='button' type='submit' name='button1' value='" . $lang ['create'] . "'>
        </form></br>";
			else if ($alliance [0] [2] == $_SESSION ["user"] [0]) {
		$output .= "[ <a class='q_link' href=\"javascript: template('forums.php?town=" . $town [0] . "&forum=0', '', '')\">" . $lang ['forum'] . "</a> ]</br></br>[ <a class='q_link' href='rank_edit.php'>" . $lang ['editRanks'] . "</a> ]</br></br>";
		$output .=  $lang ['members'] . ":</br>";
				for($i = 0; $i < count ( $alliance [1] ) - 1; $i ++)
		$output .=  "[<a class='q_link' href='a_kick.php?id=" . $alliance [1] [$i] [0] . "'>x</a>] <a class='q_link' href='profile_view.php?id=" . $alliance [1] [$i] [0] . "'>" . $alliance [1] [$i] [1] . "</a> - " . $alliance [1] [$i] [14] . "</br>";
		$output .=  "</br>" . $lang ['peacePacts'] . ":</br>";
				for($i = 0; $i < count ( $alliance [2] ) - 1; $i ++) {
					$a1 = alliance ( $alliance [2] [$i] [1] );
					$a2 = alliance ( $alliance [2] [$i] [2] );
		$output .=  "[<a class='q_link' href='dis_peace.php?a1=" . $a1 [0] . "&a2=" . $a2 [0] . "'>x</a>] " . $a1 [1] . "-" . $a2 [1] . "</br>";
				}
		$output .=  "</br>" . $lang ['warDecs'] . ":</br>";
				for($i = 0; $i < count ( $alliance [3] ) - 1; $i ++) {
					$a1 = alliance ( $alliance [3] [$i] [1] );
					$a2 = alliance ( $alliance [3] [$i] [2] );
		$output .=  $a1 [1] . "-" . $a2 [1] . "</br>";
				}
		$output .=  "<ul id='tabs'>
	    <li><a href='#invite'>" . $lang ['invite'] . "</a></li>
	    <li><a href='#proposePeace'>" . $lang ['proposePeace'] . "</a></li>
	    <li><a href='#decWar'>" . $lang ['decWar'] . "</a></li>
	    <li><a href='#allyName'>" . $lang ['allyName'] . "</a></li>
	    <li><a href='#delAlly'>" . $lang ['delAlly'] . "</a></li>
	</ul>
	<div class='tabContent' id='invite'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
          <form name='form2' method='post' action='invite.php?town=" . $_GET ["town"] . "'>
            <p>" . $lang ['playerName'] . ": 
            <input class='textbox' type='text' name='name'>
            <input class='button' type='submit' name='button2' value='" . $lang ['invite'] . "'></td></tr></p>
		  </form>
		  </table>
		 </div>
	</div>
	<div class='tabContent' id='proposePeace'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
          <form name='form3' method='post' action='pact.php?type=0&town=" . $_GET ["town"] . "'>
            <p>" . $lang ['allyName'] . ": 
            <input class='textbox' type='text' name='name'>
            <input class='button' type='submit' name='button3' value='" . $lang ['proposePeace'] . "'></td></tr></p>
		  </form>
		  </table>
		 </div>
	</div>
	<div class='tabContent' id='decWar'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
          <form name='form4' method='post' action='pact.php?type=1&town=" . $_GET ["town"] . "'>
            <p>" . $lang ['allyName'] . ": 
            <input class='textbox' type='text' name='name'>
            <input class='button' type='submit' name='button4' value='" . $lang ['decWar'] . "'></td></tr></p>
		  </form>
		  </table>
		 </div>
	</div>
	<div class='tabContent' id='allyName'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
		  <form name='form5' method='post' action='a_edit.php?town=" . $_GET ["town"] . "'>
            <p>" . $lang ['allyName'] . ": 
            <input class='textbox' type='text' name='name' value='" . $alliance [0] [1] . "'></p>
			<p>" . $lang ['allyDesc'] . ":</p>
            <p><textarea class='textbox' name='desc' cols='45' rows='7'>" . $alliance [0] [3] . "</textarea></p>
            <p><input class='button' type='submit' name='button5' value='" . $lang ['save'] . "'></p>
          </form>
		  </td></tr>
		  </table>
		 </div>
	</div>
	<div class='tabContent' id='delAlly'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
		  <form name='form6' method='post' action='a_del.php'>
            <p>" . ucfirst ( $lang ['password'] ) . ": 
            <input class='textbox' type='password' name='pass'>
            <input class='button' type='submit' name='button6' value='" . $lang ['delAlly'] . "'></p>
          </form>
		  </td></tr>
		  </table>
		 </div>
	</div>";
			} else {
		$output .=  "[ <a class='q_link' href=\"javascript: template('forums.php?town=" . $town [0] . "&forum=0', '', '')\">" . $lang ['forum'] . "</a> ]</br></br>" . $lang ['members'] . ":</br>";
				for($i = 0; $i < count ( $alliance [1] ) - 1; $i ++)
		$output .=  "<a class='q_link' href='profile_view.php?id=" . $alliance [1] [$i] [0] . "'>" . $alliance [1] [$i] [1] . "</a> - " . $alliance [1] [$i] [14] . "</br>";
		$output .=  "</br>" . $lang ['peacePacts'] . ":</br>";
				for($i = 0; $i < count ( $alliance [2] ) - 1; $i ++) {
					$a1 = alliance ( $alliance [2] [$i] [1] );
					$a2 = alliance ( $alliance [2] [$i] [2] );
		$output .=  $a1 [1] . "-" . $a2 [1] . "</br>";
				}
		$output .=  "</br>" . $lang ['warDecs'] . ":</br>";
				for($i = 0; $i < count ( $alliance [3] ) - 1; $i ++) {
					$a1 = alliance ( $alliance [3] [$i] [1] );
					$a2 = alliance ( $alliance [3] [$i] [2] );
		$output .=  $a1 [1] . "-" . $a2 [1] . "</br>";
				}
		$output .=  "
	<ul id='tabs'>
	    <li><a href='#allyName'>" . $lang ['allyName'] . "</a></li>
	    <li><a href='#quitAlly'>" . $lang ['quitAlly'] . "</a></li>
	</ul>
	<div class='tabContent' id='allyName'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse' width='440' border='1'>
		  <tr><td>
		  </br>
            <p>" . $lang ['allyName'] . ": " . $alliance [0] [1] . "</p>
			<p>" . $lang ['allyDesc'] . ":</p>
            <p><textarea class='textbox' name='desc' cols='45' rows='7' readonly='true'>" . $alliance [0] [3] . "</textarea></p>
		  </br>
		  </td></tr>
		  </table>
		 </div>
	</div>
	<div class='tabContent' id='quitAlly'>
                 <div>
		  <table class='q_table' style='border-collapse: collapse; text-align: center' width='440' border='1'>
		  <tr><td>
		  </br>
		  <p>" . $lang ['allyName'] . ": " . $alliance [0] [1] . "</p>
		  <form name='form7' method='post' action='a_quit.php'>
            <input class='button' type='submit' name='button7' value='" . $lang ['quitAlly'] . "'></p>
          </form>
		  </td></tr>
		  </table>
		 </div>
	</div>";
			}
		} else
		$output .=  $lang ['constrBuilding'];
		
		$output .= ads(1,"bottom");
		$output .= about(); 
		echo $output;
?>
